<ui:composition template="mainTemplate.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets" 
                >
    <ui:define name="title">Browse</ui:define> 
    <ui:define name="content">
        <f:metadata>
            <f:viewParam id="cat" name="cat" value="#{browseController.cat}" />        
        </f:metadata>

        <h:dataTable value="#{browseController.items}" var="item"
                     bgcolor="#fafafa" border="0" cellpadding="5" cellspacing="3"
                     first="0" width="50%" frame="border" styleClass="dataTable">
            <h:column>
                <f:facet name="header">
                    Name
                </f:facet>
                <h:link outcome="pretty:fileinfo">
                    #{item.name}
                    <f:param name="id" value="#{item.id}"/>
                </h:link>
            </h:column>
            <h:column>
                <f:facet name="header">
                    Description
                </f:facet>
                <h:outputText value="#{item.description}"/>
            </h:column> 
            <h:column>
                <f:facet name="header">
                    Category
                </f:facet>
                <h:link outcome="pretty:browse">
                    #{item.category.name}
                    <f:param name="cat" value="#{item.category.id}"/>
                </h:link>
            </h:column>

            <h:column>
                <f:facet name="header">
                    User
                </f:facet>
                <h:link outcome="pretty:profile">
                    #{item.user.firstname} #{item.user.lastname}
                    <f:param name="id" value="#{item.user.id}"/>
                </h:link>
            </h:column>

            <h:column rendered="false">
                <h:form><h:commandButton action="#{browseController.deleteFile(item.id)}" value="Delete"/></h:form>
            </h:column>
        </h:dataTable>
        <br/>
        <h:outputText value="#{browseController.pagination.pageFirstItem + 1}..#{browseController.pagination.pageLastItem + 1}/#{browseController.pagination.itemsCount}"/>
        <br/>
        <h:form>
            <h:commandLink action="#{browseController.previous}" value="Previous #{browseController.pagination.pageSize}" rendered="#{browseController.pagination.hasPreviousPage}"/> 
            <h:commandLink action="#{browseController.next}" value="Next #{browseController.pagination.pageSize}" rendered="#{browseController.pagination.hasNextPage}"/>
        </h:form>
    </ui:define>    
</ui:composition>
